package main

import "fmt"

func main() {
	//只声明，不赋值，默认值是0
	var arr [10]int
	fmt.Println(arr)

	//声明，赋值，前面两个值是1，2，其余值默认是0
	var arr2 [10]int = [10]int{1, 2}
	fmt.Printf("type of arr2 = %T\n", arr2)

	//省略类型
	var c = [5]int{1, 2}
	fmt.Println(c)

	d := [5]int{6, 2}
	fmt.Println(d)

	// 使用 ... 代替数组长度
	autoLen := [...]string{"auto1", "auto2", "auto3"}
	fmt.Println("autoLen = ", autoLen)

	// 方式1，使用range遍历
	for i, v := range c {
		fmt.Println("index = ", i, "value = ", v)
	}
	// 读取数组长度
	fmt.Println("len(a) = ", len(c))

	//方式二，for循环下标遍历
	for i := 0; i < len(c); i++ {
		fmt.Printf("i = %d\n", d[i])
	}

	d[3] = 100
	fmt.Printf("%d\n", d)

	// 二维数组
	a := [3][2]int{
		{0, 1},
		{2, 3},
		{4, 5},
	}
	fmt.Println("a = ", a)

	// 三维数组
	b := [3][2][2]int{
		{{0, 1}, {2, 3}},
		{{4, 5}, {6, 7}},
		{{8, 9}, {10, 11}},
	}
	fmt.Println("b = ", b)

	// 多维数组遍历时，需要使用嵌套for循环遍历
	for i, v := range a {
		fmt.Println("index = ", i, "value = ", v)
		for j, inner := range v {
			fmt.Println("inner, index = ", j, "value = ", inner)
		}
	}

}
